package derby;

import java.sql.DriverManager;

/**
 * @author ex_chenzy59
 * @since 2025/3/4
 *
 */
public class Derby嵌入式模式使用 {
    public static void main(String[] args) {
        try {

            // 连接数据库，如果数据库不存在，则创建数据库
            var url = "jdbc:derby:test;create=true;user=admin;password=94Chenzy.";
            var conn = DriverManager.getConnection(url);
            conn.setAutoCommit(false);
            var statement = conn.createStatement();
            /*By always和by default是说明生成这个IDENTITY的方式。By always是完全由系统自动生成。by default是可以由用户来指定一个值*/
            String sql = """
                create table user(
                id int not null generated by always as identity,
                name nvarchar(20),
                ps nvarchar(20),
                constraint P_KEY_user primary key(id));
                """;
            statement.execute(sql);
            System.out.println(sql);
            sql = "create unique index USER_NAME_INDEX on user (name ASC)";
            statement.execute(sql);
            statement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        var text= """
                
                
                                
                                
                                
                                
                                
                                
                
                
                
                
                
                
                
                """;

    }
}
